/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import modelo.cliente;
import persistencia.JdbcConnector;

/**
 *
 * @author Chris
 */
public class Controladora {

    protected Controladora() {
    }

    /**
     * 
     * @return
     */
    public static Controladora instance() {
        if (uniqueInstance == null) {
            uniqueInstance = new Controladora();
        }
        return uniqueInstance;
    }

    public void agregarCliente(cliente nuevo) {
        JdbcConnector DB = new JdbcConnector("mysql", "localhost", "3306", "ventas");
        try {
            Connection con = DB.getConnection();
            PreparedStatement stmt = con.prepareStatement(CMD_INSERTAR_CLIENTE);
            stmt.setString(1, nuevo.getNombre());
            stmt.setString(2, nuevo.getNickname());
            stmt.setInt(3, nuevo.getCedula());
            stmt.setString(4, nuevo.getContrasena());
            stmt.setString(5, nuevo.getTelf());
            stmt.setString(6, nuevo.getDireccion());
            stmt.setString(7, nuevo.getEmail());
            stmt.setString(8, nuevo.getTarjetaCredito());
            stmt.execute();
            con.close();
        } catch (Exception e) {
            System.out.println(e.toString());
        }

        /*  try{
        PreparedStatement stmt = null;
        Connection cx = DatabaseUtil.getConnectionFactory().getConnection();
        stmt = cx.prepareStatement(CMD_INSERTAR_CLIENTE);
        stmt.setString(1, nuevo.getNombre());
        stmt.setString(2,nuevo.getNickname());
        stmt.setInt(3,nuevo.getCedula());
        stmt.setString(4, nuevo.getContrasena());
        stmt.setString(5, nuevo.getTelf());
        stmt.setString(6, nuevo.getDireccion());
        stmt.setString(7, nuevo.getEmail());
        stmt.setString(8, nuevo.getTarjetaCredito());
        stmt.executeQuery();
        stmt.close();
        }
        catch(Exception e)
        {
        System.out.println(e.toString());
        }*/
    }
    private static Controladora uniqueInstance = null;
    private static String CMD_INSERTAR_CLIENTE = "INSERT INTO USUARIO VALUES (?,?,?,?,?,?,?,?)";
}
